<template>
  <div>
    <!-- 面包屑 -->
    <div class="home-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item >知识图库</el-breadcrumb-item>
        <el-breadcrumb-item >关系查询</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="entityquery-content">

      <div class="entityquery-content-header">
        <!-- 查询实体 -->
        <el-input v-model="queryForm.entity1" placeholder="查询实体1" :style="{width:200+'px',marginRight:50+'px'}"></el-input>
        <!-- 选择关系 -->
        <el-select v-model="queryForm.relation" placeholder="选择关系" :style="{width:150+'px',marginRight:50+'px'}">
          <el-option
            v-for="item in relationOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>

        <!-- 查询实体2 -->
        <el-input placeholder="查询实体2" v-model="queryForm.entity2" :style="{width:200+'px',marginRight:50+'px'}"> </el-input>

        <el-button type="primary" @click="entityQuery">查询</el-button>
      </div>


      <div class="entityquery-content-title">
<!--        <span>热门搜索：</span>
        <span>制药工艺</span> -->
      </div>

      <div class="entityquery-content-chart">
        <!-- 关系图 -->
        <div  style="height: 500px;">
          <span>关系图</span>
          <div>
            <relation-echarts :chartsData="chartsData" v-on:relationList="relationList"></relation-echarts>
          </div>
        </div>
        <!-- 关系列表 -->
        <div>
          <span>关系列表</span>
          <el-table
            :data="tableData"
            border
            style="width: 100%;">
            <el-table-column
              prop="target"
              label="实体一">
            </el-table-column>
            <el-table-column
              prop="value"
              label="关系">
            </el-table-column>
            <el-table-column
              prop="source"
              label="实体二">
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import KMaintainApi from '@/api/kMaintainApi'
  import RelationEcharts from './echarts/relationQueryEcharts'
  export default{
    name:"实体查询",
    data(){
      return{
        input3:"",
        tableData: [],
        // 关系list
        relationOptions: [],

        // 实体查询form
        queryForm:{
          entity1:'',
          entity2:'',
          relation:'',
        },
        value: '',

        // chartsData  图表数据
        chartsData:{}

      }
    },
    components:{
      RelationEcharts
    },
    methods:{
      // 关系list查询
      getRelationList(){
        KMaintainApi.kMaintainRelationList().then(res => {
          if(res.data.status === "200"){
            res.data.data.map(val => {
              var obj = {
                label:'',
                value:''
              }
              obj.label = val
              obj.value = val
              this.relationOptions.push(obj)
            })
          }
        })
      },
      // 实体关系查询
      entityQuery(){
        KMaintainApi.kMaintainRelationQuery(this.queryForm).then(res => {
          if(res.data.status === "200"){
            this.chartsData = res.data.data

            // 将返回来的数据修改一下
            this.chartsData.entity1 = this.queryForm.entity1
          }
        })
      },

      // 监听关系列表
      relationList(list){
        this.tableData = list
      }
    },
    created() {
      this.getRelationList()
    }
  }
</script>

<style scoped="scoped">
  .entityquery-content{
    background-color: #FFFFFF;
    border-radius: 8px;
    padding: 20px;
  }
  .entityquery-content-title{
    padding: 10px;
    color: rgb(98, 98, 98);
    border-bottom: 1px solid #DCDFE6;
  }
  .entityquery-content-title span:nth-child(2){
    color: rgb(26, 175, 241);
  }
  .entityquery-content-chart{
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
  }
  .entityquery-content-chart div:nth-child(1){
    flex: 3;
    /* height: 100%; */
    display: flex;
    margin-right: 30px;
    flex-direction: column;
    /* border: 1px solid #C0C4CC; */
  }
  .entityquery-content-chart div:nth-child(2){
    flex: 1;
    height: 100%;
    border: 1px solid #C0C4CC;
  }
  .entityquery-content-chart div span{
    display: block;
    height: 40px;
    line-height: 40px;
    padding-left: 20px;
    background-color: rgb(245, 245, 245);
    box-shadow: 1px 1px 5px #909399;
  }
  .entityquery-content-header{
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
</style>
